home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
examples.arc
/
EXAMPL18.PRO
< prev
next >
Wrap
Text File
|
1986-10-07
|
798b
|
33 lines
/* Program 18 */
/*
Goals to enter are on page 67 of the manual.
*/
predicates
solve(real,real,real)
reply(real,real,real)
mysqrt(real,real,real)
equal(real,real)
clauses
solve(A,B,C) :-
D = B*B-4*A*C, reply(A,B,D), nl.
reply(_,_,D) :- D < 0, write("No solution"), !.
reply(A,B,D) :-
D = 0, X=-B/(2*A), write("x=",X), !.
reply(A,B,D) :-
mysqrt(D,D,SqrtD),
X1 = (-B + SqrtD)/(2*A),
X2 = (-B - SqrtD)/(2*A),
write("x1 = ",X1," and x2 = ",X2).
mysqrt(X,Guess,Root) :-
NewGuess = Guess-(Guess*Guess-X)/2/Guess,
not(equal(NewGuess,Guess)),!,
mysqrt(X,NewGuess,Root).
mysqrt(_,Guess,Guess).
equal(X,Y) :-
X/Y > 0.99999 , X/Y < 1.00001.